import {
	GetRecommendSongSheetInfo,
	GetRecommendSongSheetAllInfo
} from "@/api/index.js"

//准备actions对象——响应组件中用户的动作
const actions = {
	// 获取歌单详情
	async getRecommendSongSheetInfo(state, id) {
		let info = await GetRecommendSongSheetInfo(id)
		state.commit('setRecommendSongSheetInfo', info['playlist'])
		state.commit('setRecommendSongSheetList', info['playlist']['tracks'])
	},

	// 获取歌单全部详情
	async GetRecommendSongSheetAllInfo(state,id){
		let info = await GetRecommendSongSheetAllInfo(id)
		state.commit('setRecommendSongSheetList', info['songs'])
		return info['songs']
	}
}
//准备mutations对象——修改state中的数据
const mutations = {
	// 修改歌单相关详情
	setRecommendSongSheetInfo(state, obj) {
		state.RecommendSongSheetInfo = obj
	},
	
	// 修改歌单内的歌曲列表
	setRecommendSongSheetList(state, obj) {
		state.RecommendSongSheetList = obj
	}
}

//准备state对象——保存具体的数据
const state = {
	RecommendSongSheetInfo: {}, // 歌单详情
	RecommendSongSheetList:[], // 歌单内的歌曲列表
}

const getters = {
	// 收藏数
	subscribedCount(state){
		let subscribedCount = state.RecommendSongSheetInfo.subscribedCount + '';
		if (subscribedCount.length >4){
			return subscribedCount.slice(0,-4) + '万'
		}
		return subscribedCount
	},
	
	// 评论数
	commentCount(state){
		let commentCount = state.RecommendSongSheetInfo.commentCount + '';
		if (commentCount.length >4){
			return commentCount.slice(0,-4) + '万'
		}
		return commentCount
	},
	
	// 分享数
	shareCount(state){
		let shareCount = state.RecommendSongSheetInfo.shareCount + '';
		if (shareCount.length >4){
			return shareCount.slice(0,-4) + '万'
		}
		return shareCount
	}
}


export default ({
	state,
	mutations,
	actions,
	getters,
	namespaced: true,
})
